/*
 * Copyright 2008 Slava Chernyak
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 */
package com.chernyak.DataAdapter;

import java.util.*;

public final class MessageSink {
	private MessageSink(){};
	
	public static enum CompilerMessageType {
		ERROR,
		WARNING,
		INFO  		
	};
	
	public static class CompilerMessage{
		public final CompilerMessageType type;
		public final String message;
		public final int ln;
		
		private CompilerMessage(CompilerMessageType type, String message, int ln) {
			this.type = type;
			this.message = message;
			this.ln = ln;
		}
		
		@Override
		public String toString() {
			return type.toString() + ": (" + ln + ") " + message;
		}
	}
	
	private static List<CompilerMessage> errors = new ArrayList<CompilerMessage>(); 
	private static List<CompilerMessage> warnings = new ArrayList<CompilerMessage>(); 
	private static List<CompilerMessage> info = new ArrayList<CompilerMessage>(); 
	
	
	public static void Error(String message, int ln) {
		CompilerMessage m = new CompilerMessage(CompilerMessageType.ERROR,
				message, ln);
		errors.add(m);
	} 
	
	public static void Warn(String message, int ln) {		
		CompilerMessage m = new CompilerMessage(CompilerMessageType.WARNING,
			message, ln);
		warnings.add(m);
	}
	
	public static CompilerMessage[] getErrors() {
		return errors.toArray(new CompilerMessage[]{});
	}
	
	public static CompilerMessage[] getWarnings() {
		return warnings.toArray(new CompilerMessage[]{});
	}
	
	public static CompilerMessage[] getInfo() {
		return info.toArray(new CompilerMessage[]{});
	}
}
